import sqlite3


class DataBase:
    # 关闭连接
    def close(self):
        self.conn.close()

    # 执行查询
    def query(self, sql: str, params):
        c = self.conn.cursor()
        c.execute(sql, params)

        result = []
        for row in c:
            result.append(row)

        return result

    # 执行非查询语句
    def execute(self, sql):
        c = self.conn.cursor()
        c.execute(sql)
        self.conn.commit()

    def batch_execute(self, sqls):
        c = self.conn.cursor()
        for sql in sqls:
            c.execute(sql)

        self.conn.commit()

    # 初始化 打开连接
    def __init__(self, db_name):
        self.conn = sqlite3.connect(db_name)
